package com.plugin.manage.service.impl;

import com.plugin.core.model.entity.SysLog;
import com.plugin.manage.mapper.SysLogMapper;
import com.plugin.manage.service.ISysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 系统日志服务实现类
 * 
 * @author mark
 * @date 2025-07-24
 */
@Slf4j
@Service
public class SysLogServiceImpl implements ISysLogService {

    @Autowired(required = false)
    private SysLogMapper sysLogMapper;

    /**
     * 添加系统日志
     * 
     * @param sysLog 系统日志对象
     * @return 插入结果
     */
    @Override
    public int add(SysLog sysLog) {
        try {
            if (sysLogMapper != null) {
                return sysLogMapper.insert(sysLog);
            }
            // 如果mapper不可用，返回0表示未插入
            log.warn("SysLogMapper is not available, log not saved: {}", sysLog);
            return 0;
        } catch (Exception e) {
            log.error("添加系统日志失败", e);
            return 0;
        }
    }
}
